<template>
    <div>
        房间号：
        <input type="text" v-model="query.Num">
        名称：
        <input type="text" v-model="query.Name">
        <input type="button" value="查询" @click="Show">
        <table border="1">
            <thead>
                <tr>
                    <th>房间号</th>
                    <th>房间名称</th>
                    <th>描述</th>
                    <th>状态</th>
                    <th>床位</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="h in data">
                    <th>{{ h.Num }}</th>
                    <th>{{ h.Name }}</th>
                    <th>{{ h.Des }}</th>
                    <th>{{ h.State?"启用":"禁用" }}</th>
                    <th>{{ h.Bed }}</th>
                    <th>
                        <input type="button" value="逻辑删除" @click="Del(h.Id)">
                    </th>
                    <th>
                        <input type="button" value="修改状态" @click="UpState(h.Id)">
                    </th>
                    <th>
                        <input type="button" value="修改" @click="Up(h.Id)">
                    </th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { validateLocaleAndSetLanguage } from 'typescript';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const data=ref([{
    "Id": 0,
  "Num": "",
  "Name": "",
  "Des": "",
  "State": true,
  "Bed": "",
  "Delete": true
}])


const query=ref({
    Name:"",
    Num:""
})



onMounted(()=>{
    Show();
})


const Show=()=>{
    axios.get("https://localhost:7198/api/Home/GetHome",{params:query.value}).then(res=>{
        data.value=res.data
    })
}


const Del=(val:any)=>{
    if(confirm('确定删除吗？')){
        axios.delete("https://localhost:7198/api/Home/Del",{params:{Id:val}}).then(res=>{
        if(res.data>0){
            alert('删除成功')
            Show();
        }
        else{
            alert('失败')
        }
    })
    }
   
}

const UpState=(val:any)=>{
    
        axios.get("https://localhost:7198/api/Home/UpdateState",{params:{Id:val}}).then(res=>{
        if(res.data>0){
            alert('修改状态成功')
            Show();
        }
        else{
            alert('失败')
        }
    })
 
}

const rour=useRouter();

const Up=(val:any)=>{
    rour.push({path:"/DetailView",query:{Id:val}})
}


</script>

